package com.zebra.gateway;

import com.zebra.gateway.protocol.GatewayCodec;
import com.zebra.gateway.protocol.GatewayHeartClientHandler;
import com.zebra.remoting.config.ServerType;
import com.zebra.remoting.connection.Connection;
import com.zebra.remoting.connection.DefaultConnectionFactory;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;

public class GatewayClient {
    private static final InternalLogger logger = InternalLoggerFactory.getInstance(GatewayClient.class);
    private DefaultConnectionFactory connectionFactory;

    private static GatewayClient client = new GatewayClient();

    private GatewayClient(){
        connectionFactory = new DefaultConnectionFactory();
        connectionFactory.registerCommandHandler(new CommandClientHandler());
        connectionFactory.registerRpcCodec(new GatewayCodec());
        connectionFactory.registerHeartbeatProcessor(new GatewayHeartClientHandler());
        connectionFactory.init();
    }

    public static GatewayClient getInstance(){
        return client;
    }

    public Connection connection(String ip, int port, int serverId)throws Exception{
        return connectionFactory.connection(ip, port, serverId, ServerType.Tms, 3000);
    }

}
